home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: Schildt <- Advanced Books
- Date: 8 Mar 96 17:26:27 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.826305987@rscernix>
- References: <8BA8405.02C70020DE.uuout@sourcebbs.com> <danpop.826121528@rscernix> <4hleu9$5ah@solutions.solon.com> <danpop.826238706@rscernix> <4ho3m3$iov@solutions.solon.com>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4ho3m3$iov@solutions.solon.com> seebs@solutions.solon.com (Peter Seebach) writes:
-
- >In article <danpop.826238706@rscernix>, Dan Pop <danpop@mail.cern.ch> wrote:
- >>In <4hleu9$5ah@solutions.solon.com> seebs@solutions.solon.com (Peter Seebach) writes:
- >>>I consider a bug subtle if the code is likely to work correctly most of the
- >>>time.
- >
- >>So, you consider "void main" and calling malloc without a declaration in
- >>scope subtle bugs :-)
- >
- >Yup. They are not obvious to a casual programmer who hasn't specifically
- >been warned about them. The latter especially; if you're looking at
- >code in the middle of a 500+ line module, how often do you remember to
- >check for relevant headers? :)
-
- My compiler _will_ warn about illegal integer to pointer conversion
- and I NEVER ignore such a warning. Moreover, even the silly cast in front
- of malloc won't prevent gcc from telling me that something silly is
- happening:
-
- ues5:~/tmp 30> cat test.c
- main()
- {
- char *p = (char *)malloc(100);
- }
- ues5:~/tmp 31> gcc test.c
- test.c: In function `main':
- test.c:3: warning: cast to pointer from integer of different size
-
- But this is because I have the "privilege" of using a system where
- pointers and int's have different sizes. It's amazing how much new free
- software has to be fixed, even today, three years after the Alpha boxes
- have hit the market.
-
- >The same book, at one point, declares
- > char *buf[128];
- >and passes the buffer to something like fgets().
-
- I'd stay away from any book which has untested examples. We are all
- human and we all make mistakes, but any serious author will, at least,
- compile his examples to be sure they're correct and will introduce the
- source code directly into the "manuscript", to be sure that no typo could
- find its way in. Many authors even document this practice, somewhere in
- the preface (e.g. the last phrase on page ix of K&R2).
-
- >I consider this much more
- >serious; it is likely to slip into real code, and will not even produce a
- >warning on certain oft-used and broken systems, like Sun's.
-
- Anybody using cc (without lint) on SunOS gets exactly what s/he deserves.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-